package gui;

import java.net.ServerSocket;
import java.net.Socket;

import javax.swing.SwingUtilities;

public class ConnectionThread extends Thread {

	private ServerSocket server;
	private MainForm mainForm;
	private boolean a;
	
	public void setServerSocket(ServerSocket server) {
		this.server = server;
	}

	@Override
	public void run() {
		while(!a){
			try {
				final Socket client = server.accept();
				if (client != null){
					SwingUtilities.invokeLater(new Runnable(){

						@Override
						public void run() {
							mainForm.initClient(client);
						}
						
					});
					a = true;
				}
			} catch (Exception e) {
				System.out.println("error");
			}
		}
	}
	
	public void threadStop(){
		a = true;
	}

	public void setMainForm(MainForm mainForm) {
		this.mainForm = mainForm;
	}

	
	
}
